export interface NetworkNodeElType {
	id: string;
	label: string;
	type: string;
	color: string;
	size: number;
	index: number;
	x: number;
	y: number;
	vx: number;
	vy: number;
	fx: number;
	fy: number;
}

export interface NodeItemType {
	id: string;
	label: string;
	type: string;
	color?: string;
	size?: number;
	backgroundImg?: string;
	gradientStops?: { offset: number; color: string; opacity?: number }[];
	gradientType?: string;
	gradientDir?: number[];
	x?: number;
	y?: number;
	vx?: number;
	vy?: number;
	_imageLoaded?: boolean;
	_imageLoadFailed?: boolean;
}

export interface LinkItemType {
	source: string;
	target: string;
	label: string;
	isHierarchy: boolean;
}

export interface RelationStyleByTypeItem {
	name?: string;
	label?: string;
	isHierarchy: boolean;
}

export type RelationStyleByType = RelationStyleByTypeItem[];

export interface NodeStyleByTypeItem {
	name?: string;
	type?: string;
	color?: string;
	size?: number;
	textPosition?: string;
	gradientType?: string;
	gradientStops?: { offset: number; color: string }[];
	gradientDir?: number[];
	backgroundImg?: string;
}

export type NodeStyleByType = NodeStyleByTypeItem[];

export type SimulationNodeType = NodeItemType & d3.SimulationNodeDatum & { size?: number };

// D3 力模拟中转换后的链接类型（source 和 target 是节点对象）
export type SimulationLinkType = LinkItemType & {
	source: SimulationNodeType;
	target: SimulationNodeType;
};

/** 节点右键菜单 */
export interface ContextMenuType {
	visible: boolean;
	x: number;
	y: number;
	currentNode: SimulationNodeType | null;
}

export interface NodeEditDialogType {
	visible: boolean;
	isAdd: boolean;
	form: {
		nodeId: string | null;
		nodeName: string;
		nodeType: string;
		relations: {
			sourceNodeId: string;
			targetNodeId: string;
			label: string;
			isHierarchy: boolean;
		}[];
	};
}

export interface NodeUpdateType {
	label: string;
	type: string;
}

export interface ValidUpdatedRelationItemType {
	sourceId: string;
	targetId: string;
	updates: {
		label: string;
		isHierarchy: boolean;
	};
	relationKey: string;
}

export interface AddRelationItemType {
	sourceNodeId: string;
	targetNodeId: string;
	label: string;
	isHierarchy: boolean;
}

export interface AddRelationResultType {
	success?: boolean;
	added: {
		index: number;
		relation: LinkItemType;
	}[];
	failed: {
		index: number;
		relation: LinkItemType;
		error: string;
	}[];
	skipped: {
		index: number;
		relation: LinkItemType;
		reason: string;
		existingRelation: LinkItemType;
	}[];
	updated: {
		index: number;
		relation: LinkItemType;
		originalData: LinkItemType;
	}[];
	total: number;
}

export interface RelationEditedType {
	oldRelation?: {
		source: string;
		target: string;
		label: string;
	};
	newRelation?: AddRelationResultType | LinkItemType | boolean | null;
	relation?: {
		source: string;
		target: string;
		label: string;
	};
}
